<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<style>
			.area {
				margin: 20px auto 0px auto;
			}
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			.mui-input-group label {
				width: 22%;
			}
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}
			.mui-content-padded {
				margin-top: 25px;
			}
			.mui-btn {
				padding: 10px;
			}
			.coranger{color:#eb533b;}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left coranger"></a>
			<h1 class="mui-title">注册</h1>
		</header>
		<div class="mui-content">
			<img src="images/p2.jpg" width="100%"  /> 
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>账号</label>
					<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入手机号">
				</div>
				<div class="mui-input-row">
					<label>密码</label>
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
				<div class="mui-input-row">
					<label>确认</label>
					<input id='password_confirm' type="password" class="mui-input-clear mui-input" placeholder="请确认密码">
				</div>
				<div class="mui-input-row">
					<label>验证码</label>
					<input id='vcode' style="width:50%;float:left" type="text" class="mui-input-clear mui-input" placeholder="请输入验证码">
					<button id="btnvcode" style="width:27%;float:right;margin-right: 1px;;" type="button" class="mui-btn">
					获得验证码
					</button>
				</div>
			</form>
			<div class="mui-content-padded">
				<button id='reg' class="mui-btn mui-btn-block mui-btn-primary" style="border: #eb533b 1px solid;background-color: #eb533b;">注册</button>
			</div>
			<div class="mui-content-padded">
				<p>已注册账户的，请点击<a href="login.html" class="coranger">登录</a></p>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script>
			(function($, doc) {
				$.init();
				$.plusReady(function() {
					
					function Trim(str)
				    { 
				        return str.replace(/(^\s*)|(\s*$)/g, ""); 
				    }
				    
				    var wait=60;
					function time(o) {
					  if (wait == 0) {
					   o.disabled=false;;   
					   o.innerHTML="获取验证码";
					   wait = 60;
					  } else { 
					 
					   o.disabled=true;;
					   o.innerHTML="重新发送(" + wait + ")";
					   wait--;
					   setTimeout(function() {
					    time(o)
					   },
					   1000)
					  }
					}
						
						
					//var settings = app.getSettings();
					var regButton = doc.getElementById('reg');
					var accountBox = doc.getElementById('account');
					var passwordBox = doc.getElementById('password');
					var passwordConfirmBox = doc.getElementById('password_confirm');
					var emailBox = doc.getElementById('vcode');
					
					var btnvcode = doc.getElementById('btnvcode');
					
					btnvcode.addEventListener('tap', function(event) {
						var motel = Trim(accountBox.value);
						if(motel == '')
						{
							plus.nativeUI.toast('手机号不能为空！');
							return;
						}
						
						//begin
							mui.ajax('http://wei.mysuntech.cn/appapi/sms/zcm.php?motel='+motel,{
								data:{
									username2:'username',
									password2:'password'
								},
								dataType:'json',//服务器返回json格式数据
								type:'post',//HTTP请求类型
								timeout:10000,//超时时间设置为10秒；        
								success:function(data){
									if(data == '1')
									{
										btnvcode.disabled=true;
										time(btnvcode);
									}
									else
									{
										plus.nativeUI.toast('验证码发送失败！');
										return;
									}
									},
								error:function(xhr,type,errorThrown){
									//异常处理；
									console.log(type);
								}
							});
					
					});
					
					regButton.addEventListener('tap', function(event) {
						var regInfo = {
							account: accountBox.value,
							password: passwordBox.value,
							email: emailBox.value
						};
						var passwordConfirm = passwordConfirmBox.value;
						if (passwordConfirm != regInfo.password) {
							plus.nativeUI.toast('密码两次输入不一致');
							return;
						}
						
						
						
						if(Trim(accountBox.value) == '')
						{
							plus.nativeUI.toast('手机号不能为空！');
							return;
						}
						
						if(Trim(emailBox.value) == '')
						{
							plus.nativeUI.toast('验证码不能为空！');
							return;
						}
						
						app.reg(regInfo, function(err) {
							if (err) {
								plus.nativeUI.toast(err);
								return;
							}
							plus.nativeUI.toast('注册成功');
							$.openWindow({
								url: 'login.html',
								id: 'login',
								show: {
									aniShow: 'pop-in'
								}
							});
						});
					});
				});
			}(mui, document));
		</script>
	</body>

</html>